<template>
	<view class="">
		<view class="acea-row row-between goods-list">
			<view class="item" @click="toDetail(item.id)" v-for="(item,index) in list" :key="index">
				<view class="img">
					<image :src="item.images?item.images.split(',')[0]:''" mode="" v-if="item.images"></image>
					<!-- <image :src="item.shopfrontPhoto?item.shopfrontPhoto.split(',')[0]:''" mode="" v-if="item.shopfrontPhoto"></image> -->
					<text class="distance" v-if="item.distance">{{kmUnit(item.distance)}}</text>
				</view>
				<view class="info">
					<view class="title line2">
						{{item.commodityName}}
					</view>
					<view class="title line2">
						{{item.serviceArea}}丨{{item.title}}
					</view>
					<view class="acea-row type-list">
						<view class="type-r" v-for="serviceCharacteristics in item.serviceCharacteristics?item.serviceCharacteristics.split(','):[]"
							:key="serviceCharacteristics">
							{{ serviceCharacteristics }}
						</view>
					</view>
					<view class="acea-row row-middle row-between price-info">
						<view class="price">
							<text>{{ item.commodityPrice || 0 }}</text>元
						</view>
					</view>
					<view class="acea-row row-middle row-between price-info">
						<view class="wants">
							剩余<text>{{ item.commodityNum || 0 }}</text>件
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'contactsList',
		props: {
			list: {
				type: Array,
				default: () => {
					return []
				}
			},
			notType: {
				type: Boolean,
				default: () => {
					return true
				}
			},
			showMask: {
				type: Boolean,
				default: () => {
					return false
				}
			}
		},
		data() {
			return {

			}
		},
		methods: {
			toDetail(id) {
				uni.navigateTo({
					url: '/pages/details/supplyChain/supplyChain?id=' + id
				})
			},
			kmUnit(m) {
				var v;
				m = Number(m)
				if (typeof m === 'number' && !isNaN(m)) {
					if (m >= 1000) {
						v = (m / 1000).toFixed(2) + 'km'
					} else {
						v = m.toFixed(2) + 'm'
					}
				} else {
					v = '0m'
				}
				return v;
			},
		}
	}
</script>

<style lang="scss">
	// 推荐
	.goods-list {
		padding: 30rpx 0;

		.item {
			width: 48%;
			border-radius: 20rpx;
			background: rgba(255, 255, 255, 1);
			margin-bottom: 24rpx;

			.img {
				position: relative;
				width: 100%;
				height: 288rpx;
				border-radius: 20rpx 20rpx 0 0;
				background: #ff0000;

				image {
					width: 100%;
					height: 100%;
					border-radius: 20rpx 20rpx 0 0;
				}

				.distance {
					position: absolute;
					bottom: 10rpx;
					left: 10rpx;
					padding: 10rxp;
					background: rgba(0, 0, 0, .3);
					color: #fff;
					border-radius: 8rpx;
				}
			}

			.info {
				padding: 18rpx;

				.title {
					font-size: 28rpx;
					font-weight: 400;
					line-height: 40rpx;
					color: rgba(0, 0, 0, 1);
				}

				.gray-text {
					font-size: 26rpx;
					font-weight: 400;
					line-height: 42rpx;
					color: rgba(128, 128, 128, 1);
				}

				.type-list {
					padding: 12rpx 0;
				}

				.type-r {
					font-size: 22rpx;
					font-weight: 400;
					color: rgba(238, 33, 45, 1);
					padding: 0 12rpx;
					height: 36rpx;
					line-height: 36rpx;
					text-align: center;
					border-radius: 4rpx;
					background: rgba(255, 232, 234, 1);
					letter-spacing: 0.4rpx;
					margin-right: 14rpx;
					margin-bottom: 10rpx;
					white-space: nowrap;
				}

				.type-b {
					font-size: 22rpx;
					font-weight: 400;
					color: rgba(82, 104, 139, 1);
					padding: 0 12rpx;
					height: 36rpx;
					line-height: 36rpx;
					text-align: center;
					border-radius: 4rpx;
					background: rgba(248, 249, 253, 1);
					letter-spacing: 0.4rpx;
					margin-right: 14rpx;
					margin-bottom: 10rpx;
					white-space: nowrap;
				}

				.price-info {
					.price {
						font-size: 24rpx;
						font-weight: 400;
						color: rgba(238, 33, 45, 1);

						text {
							font-size: 36rpx;
							font-weight: 700;
						}
					}

					.wants {
						font-size: 24rpx;
						font-weight: 400;
						color: rgba(166, 166, 166, 1);
					}
				}
			}
		}
	}
</style>